<?php
class Hotel extends HotelPeer
{
	function Hotel()
	{
		parent::HotelPeer();
	}
	
	
	public static function getAllHotels($active=1, $orderby='id', $limit=NULL)
	{
		$db = new Database();
		if ($active != 1)
			$active = 0;
		$query = "SELECT id FROM hotel WHERE active = $active ORDER BY $orderby ";
		$db->query($query);
		$result = $db->result;
		$ids = $db->fetch_array($result);
		$hotels = array();
		if ($ids)
			foreach ($ids as $id) {
				$hotel = new Hotel();
				$hotel->select($id['id']);
				$hotels[] = $hotel;
			}
			
		return $hotels;
	}
	
	
	function getAllRooms()
	{
		$db = new Database();
		$query = "SELECT id FROM room WHERE hotel_id = ".$this->getid();
		$db->query($query);
		$result = $db->result;
		$ids = $db->fetch_array($result);
		$rooms = array();
		if ($ids)
			foreach ($ids as $id) {
				$room = new Room();
				$room->select($id['id']);
				$rooms[] = $room;
			}
		return $rooms;
	}
	
	
	
	function getAllPictures()
	{
		$picture_ids = $this->getpictures();
		$picture_ids = json_decode($picture_ids, true);
		$pictures = array();
		if ($picture_ids)
			foreach ($picture_ids as $id) 
				if ($id) {
					$pic = new Picture();
					$pic->select($id);
					$pictures[] = $pic;
				}

		return $pictures;	
	}
	
	// Get most promotion (maxi promo of rooms)
	function getPromotion()
	{
		$rooms = $this->getAllRooms();
		$promo = 0;
		foreach ($rooms as $room)
			if ($room->getpromotion() > $promo)
				$promo = $room->getpromotion();
		return $promo;
	}
	
	// Get min price (mini price of rooms)
	function getPrice()
	{
		$rooms = $this->getAllRooms();
		$price = PHP_INT_MAX;
		$currency = 19;
		foreach ($rooms as $room)
			if ($room->getprice() < $price) {
				$price = $room->getprice();
				$currency = $room->getcurrency();
			}
		return $price;
	}
	
	// Get currency for min price
	function getCurrency()
	{
		$rooms = $this->getAllRooms();
		$price = PHP_INT_MAX;
		$currency = 19;
		foreach ($rooms as $room)
			if ($room->getprice() < $price) {
				$price = $room->getprice();
				$currency = $room->getcurrency();
			}
		return $currency;
	}
}
?>